package com.richpencil.modules.service.impl;

import com.richpencil.modules.service.EmailService;
import com.richpencil.modules.ki.domain.EmailConfig;
import com.richpencil.modules.ki.domain.vo.EmailVo;
//import me.zhengjie.repository.EmailRepository;
//import me.zhengjie.utils.ElAdminConstant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @date 2018-12-26
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class EmailServiceImpl implements EmailService {

	@Override
	public EmailConfig update(EmailConfig emailConfig, EmailConfig old) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public EmailConfig find() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception {
		// TODO Auto-generated method stub
		
	}

	/*
	 * @Autowired private me.zhengjie.repository.EmailRepository emailRepository;
	 * 
	 * @Override
	 * 
	 * @Transactional(rollbackFor = Exception.class) public EmailConfig
	 * update(EmailConfig emailConfig, EmailConfig old) { try {
	 * if(!emailConfig.getPass().equals(old.getPass())){ // 对称加密
	 * emailConfig.setPass(EncryptUtils.desEncrypt(emailConfig.getPass())); } }
	 * catch (Exception e) { e.printStackTrace(); } return
	 * emailRepository.save(emailConfig); }
	 * 
	 * @Override public EmailConfig find() { Optional<EmailConfig> emailConfig =
	 * emailRepository.findById(1L); if(emailConfig.isPresent()){ return
	 * emailConfig.get(); } else { return new EmailConfig(); } }
	 * 
	 * @Override
	 * 
	 * @Transactional(rollbackFor = Exception.class) public void send(EmailVo
	 * emailVo, EmailConfig emailConfig){ if(emailConfig == null){ throw new
	 * BadRequestException("请先配置，再操作"); }
	 *//**
		 * 封装
		 */
	/*
	 * MailAccount account = new MailAccount();
	 * account.setHost(emailConfig.getHost());
	 * account.setPort(Integer.parseInt(emailConfig.getPort()));
	 * account.setAuth(true); try { // 对称解密
	 * account.setPass(EncryptUtils.desDecrypt(emailConfig.getPass())); } catch
	 * (Exception e) { throw new BadRequestException(e.getMessage()); }
	 * account.setFrom(emailConfig.getUser()+"<"+emailConfig.getFromUser()+">");
	 * //ssl方式发送 //account.setStartttlsEnable(true); String content =
	 * emailVo.getContent();
	 *//**
		 * 发送
		 *//*
			 * try { Mail.create(account) .setTos(emailVo.getTos().toArray(new
			 * String[emailVo.getTos().size()])) .setTitle(emailVo.getSubject())
			 * .setContent(content) .setHtml(true) //关闭session .setUseGlobalSession(false)
			 * .send(); }catch (Exception e){ throw new BadRequestException(e.getMessage());
			 * } }
			 */
}
